home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / daemons / ipServer / stat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-26  |  10.5 KB  |  340 lines

  1. /* 
  2.  * stat.c --
  3.  *    
  4.  *    Routines to print statistics about the IP server.
  5.  *
  6.  * Copyright 1987 Regents of the University of California
  7.  * All rights reserved.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/stat.c,v 1.5 89/04/10 16:36:03 mgbaker Exp $ SPRITE (Berkeley)";
  19. #endif not lint
  20.  
  21.  
  22. #include "sprite.h"
  23. #include "ipServer.h"
  24. #include "stat.h"
  25.  
  26. #include "time.h"
  27. #include "proc.h"
  28. #include "dev/net.h"
  29.  
  30. Stat_Info    stats;
  31.  
  32. static Proc_ResUsage    lastUsage;
  33. static void ComputeDiff();
  34. static char statDumpFile[100];
  35.  
  36.  
  37. /*
  38.  *----------------------------------------------------------------------
  39.  *
  40.  * Stat_Command --
  41.  *
  42.  *    Interprets IOC_NET_STATS command.
  43.  *
  44.  * Results:
  45.  *    None.
  46.  *
  47.  * Side effects:
  48.  *    Statistics may be updated or printed.
  49.  *
  50.  *----------------------------------------------------------------------
  51.  */
  52.  
  53. extern char myHostName[];
  54.  
  55. int
  56. Stat_Command(command)
  57.     unsigned int command;
  58. {
  59.  
  60.     switch (command & 0xFFFF) { 
  61.     case NET_STATS_RESET:
  62.         bzero((Address) &stats,sizeof(stats));
  63. #ifndef KERNEL
  64.         Sys_GetTimeOfDay(&stats.startTime, (int *) NULL, (Boolean *) NULL);
  65.         Proc_GetResUsage(PROC_MY_PID, &lastUsage);
  66. #endif
  67.         break;
  68.  
  69.     case NET_STATS_DUMP:
  70. #ifndef KERNEL
  71.         (void) sprintf(statDumpFile, 
  72.             "/tmp/ipServer.%s.%d", myHostName, command >> 16);
  73. #endif
  74.         Stat_PrintInfo(-1, -1);
  75.         break;
  76.     }
  77. }
  78.  
  79.  
  80. /*
  81.  *----------------------------------------------------------------------
  82.  *
  83.  * Stat_PrintInfo --
  84.  *
  85.  *    Prints a summary of the statistics collected so far.
  86.  *
  87.  * Results:
  88.  *    None.
  89.  *
  90.  * Side effects:
  91.  *    Statistics are printed on the standard error stream or to a file.
  92.  *
  93.  *----------------------------------------------------------------------
  94.  */
  95.  
  96. /*ARGSUSED*/
  97. int
  98. Stat_PrintInfo(sigNum, sigCode)
  99.     int        sigNum;        /* > 0 if called by signal handler. */
  100.     int        sigCode;    /* used as stat file version #. */
  101. {
  102.     Proc_ResUsage    usage;
  103.     Proc_ResUsage    diff;
  104.     Time        curTime;
  105.     int            localOffset;
  106.     char        timeString[TIME_CVT_BUF_SIZE];
  107. #ifndef KERNEL
  108.     extern unsigned int fsNumTimeoutEvents;
  109.     extern unsigned int fsNumStreamEvents;
  110.     FILE        *stream;
  111.     if (sigNum == -1) {
  112.     stream = fopen(statDumpFile, "w");
  113.     } else {
  114.     stream = stderr;
  115.     }
  116. #else
  117.     int stream = 0;
  118. #endif
  119.  
  120.     Sys_GetTimeOfDay(&curTime, &localOffset, (Boolean *) NULL);
  121. #ifndef sun4
  122.     {
  123.     char    *Version();
  124.     (void) fprintf(stream, "IP Server stats:  %s\n\n", (char *) Version());
  125.     }
  126. #endif sun4
  127.  
  128.     Time_ToAscii(stats.startTime.seconds + 60 * (localOffset+60), 
  129.         FALSE, timeString);
  130.     (void) fprintf(stream, "Started at:   %s\n", timeString);
  131.  
  132.     Time_ToAscii(curTime.seconds + 60 * (localOffset+60), FALSE, timeString);
  133.     (void) fprintf(stream, "Current time: %s\n", timeString);
  134.  
  135.     Time_Subtract(curTime, stats.startTime, &curTime);
  136.     Time_ToAscii(curTime.seconds, TRUE, timeString);
  137.     (void) fprintf(stream, "Difference:   %s\n", timeString);
  138.  
  139. #ifndef KERNEL
  140.     Proc_GetResUsage(PROC_MY_PID, &usage);
  141.     ComputeDiff(&usage, &lastUsage, &diff);
  142.     (void) fprintf(stream, "\nResource Usage:\n");
  143.     (void) fprintf(stream, " %16s %16s %11s %11s\n",
  144.         "kernel CPU", "user CPU", "invol.cs", "vol.cs");
  145.     (void) fprintf(stream, " %9d.%06d %9d.%06d %11d %11d\n",
  146.         diff.kernelCpuUsage.seconds,
  147.         diff.kernelCpuUsage.microseconds,
  148.         diff.userCpuUsage.seconds,
  149.         diff.userCpuUsage.microseconds,
  150.         diff.numQuantumEnds,
  151.         diff.numWaitEvents);
  152. #endif
  153.     (void) fprintf(stream, "Socket:\n");
  154.     (void) fprintf(stream, " %11s %11s %11s %11s %11s %11s\n",
  155.         "open","close", "read", "write", "ioctl", "select");
  156.     (void) fprintf(stream, " %11d %11d %11d %11d %11d %11d\n",
  157.         stats.sock.open,
  158.         stats.sock.close,
  159.         stats.sock.read,
  160.         stats.sock.write,
  161.         stats.sock.ioctl,
  162.         stats.sock.select);
  163.     (void) fprintf(stream, " %11s %11s %11s %11s %11s %11s\n",
  164.         "append", "app.part", "part.bytes", "app.fail", "remove", "fetch");
  165.     (void) fprintf(stream, " %11d %11d %11d %11d %11d %11d\n",
  166.         stats.sock.buffer.append,
  167.         stats.sock.buffer.appendPartial,
  168.         stats.sock.buffer.appPartBytes,
  169.         stats.sock.buffer.appendFail,
  170.         stats.sock.buffer.remove,
  171.         stats.sock.buffer.fetch);
  172.     (void) fprintf(stream, " %11s %11s %11s %11s %11s %11s\n",
  173.         "copies", "bytes copied", "rte $hits %", "dispatches", 
  174.         "timeouts", "streams");
  175.     (void) fprintf(stream, " %11d %11d %11d %11d %11d %11d\n",
  176.         stats.sock.buffer.copy,
  177.         stats.sock.buffer.copyBytes,
  178.         (stats.misc.routeCalls != 0 ? 
  179.         (100*stats.misc.routeCacheHits)/stats.misc.routeCalls : 0),
  180.         stats.misc.dispatchLoop,
  181. #ifndef KERNEL
  182.         fsNumTimeoutEvents,
  183.         fsNumStreamEvents);
  184. #else
  185.         0, 0);
  186. #endif
  187.  
  188.  
  189.     (void) fprintf(stream, "\n");
  190.  
  191.     (void) fprintf(stream, "TCP:\n");
  192.     (void) fprintf(stream, " %11s %11s %11s %11s %11s %11s\n",
  193.         "send: total", "data bytes", "data pack","ack only", "win probe", 
  194.         "win update");
  195.     (void) fprintf(stream, " %11d %11d %11d %11d %11d %11d\n",
  196.         stats.tcp.send.total,
  197.         stats.tcp.send.byte,
  198.         stats.tcp.send.pack,
  199.         stats.tcp.send.acks,
  200.         stats.tcp.send.probe,
  201.         stats.tcp.send.winUpdate);
  202.     (void) fprintf(stream, " %11s %11s %11s %11s %11s %11s\n",
  203.         "recv: total","bad", "data: ok","dupl.", "part dupl.", "bad order");
  204.     (void) fprintf(stream, " %11d %11d %11d %11d %11d %11d\n",
  205.         stats.tcp.recv.total,
  206.         stats.tcp.recv.badChecksum +
  207.         stats.tcp.recv.badOffset +
  208.         stats.tcp.recv.shortLen,
  209.         stats.tcp.recv.pack,
  210.         stats.tcp.recv.dupPack,
  211.         stats.tcp.recv.partDupPack,
  212.         stats.tcp.recv.ooPack);
  213.     (void) fprintf(stream, " %11s %11s %11s %11s %11s %11s\n",
  214.         "data bytes", "data > win", "after close", "win probe", 
  215.         "win update","");
  216.     (void) fprintf(stream, " %11d %11d %11d %11d %11d %11d\n",
  217.         stats.tcp.recv.byte,
  218.         stats.tcp.recv.packAfterWin,
  219.         stats.tcp.recv.afterClose,
  220.         stats.tcp.recv.winProbe,
  221.         stats.tcp.recv.winUpd,
  222.         0);
  223.     (void) fprintf(stream, " %11s %11s %11s %11s %11s %11s\n",
  224.         "acks", "dupl. ack", "ack > win", "urgent", "urg only","");
  225.     (void) fprintf(stream, " %11d %11d %11d %11d %11d %11d\n",
  226.         stats.tcp.recv.ackPack,
  227.         stats.tcp.recv.dupAck,
  228.         stats.tcp.recv.ackTooMuch,
  229.         stats.tcp.recv.urgent,
  230.         stats.tcp.recv.urgentOnly,
  231.         0);
  232.     (void) fprintf(stream, " %11s %11s %11s %11s %11s %11s\n",
  233.         "timer: tot.", "delay ack","retrans", "retr.drop", "persist", 
  234.         "2*msl");
  235.     (void) fprintf(stream, " %11d %11d %11d %11d %11d %11d\n",
  236.         stats.tcp.timerCalls,
  237.         stats.tcp.delayAck,
  238.         stats.tcp.rexmtTimeout,
  239.         stats.tcp.timeoutDrop,
  240.         stats.tcp.persistTimeout,
  241.         stats.tcp.mslTimeout);
  242.     (void) fprintf(stream, " %11s %11s %11s\n",
  243.         "total keeps", "dropped", "probes");
  244.     (void) fprintf(stream, " %11d %11d %11d\n",
  245.         stats.tcp.keepTimeout,
  246.         stats.tcp.keepDrops,
  247.         stats.tcp.keepProbe);
  248.  
  249.     (void) fprintf(stream, "\n");
  250.     (void) fprintf(stream, "UDP:\n");
  251.     (void) fprintf(stream, " %11s %11s %11s %11s %11s %11s\n",
  252.         "recv: total", "accepts", "deamons", "bad", "#bytes", "acc.bytes");
  253.     (void) fprintf(stream, " %11d %11d %11d %11d %11d %11d\n",
  254.         stats.udp.recv.total,
  255.         stats.udp.recv.accepted,
  256.         stats.udp.recv.daemon,
  257.         stats.udp.recv.shortLen+
  258.         stats.udp.recv.badChecksum,
  259.         stats.udp.recv.dataLen,
  260.         stats.udp.recv.acceptLen);
  261.     (void) fprintf(stream, " %11s %11s\n",
  262.         "send: total", "#bytes");
  263.     (void) fprintf(stream, " %11d %11d\n",
  264.         stats.udp.send.total,
  265.         stats.udp.send.dataLen);
  266.  
  267.     (void) fprintf(stream, "\n");
  268.     (void) fprintf(stream, "ICMP:\n");
  269.     (void) fprintf(stream, " %11s %11s %11s %11s %11s\n",
  270.         "recv: total", "short", "bad sum", "bad type", "bad code");
  271.     (void) fprintf(stream, " %11d %11d %11d %11d %11d\n",
  272.         stats.icmp.total, 
  273.         stats.icmp.shortLen, 
  274.         stats.icmp.badChecksum, 
  275.         stats.icmp.badType, 
  276.         stats.icmp.badCode);
  277.     (void) fprintf(stream, " %11s %11s %11s %11s %11s\n",
  278.       "unreachable", "redirect", "src quench", "time exceed", "param prob");
  279.     (void) fprintf(stream, " %11d %11d %11d %11d %11d\n",
  280.         stats.icmp.inHistogram[NET_ICMP_UNREACHABLE],
  281.         stats.icmp.inHistogram[NET_ICMP_REDIRECT],
  282.         stats.icmp.inHistogram[NET_ICMP_SOURCE_QUENCH],
  283.         stats.icmp.inHistogram[NET_ICMP_TIME_EXCEED],
  284.         stats.icmp.inHistogram[NET_ICMP_PARAM_PROB]);
  285.     (void) fprintf(stream, " %11s %11s %11s %11s\n",
  286.         "echo", "timestamp", "info", "mask");
  287.     (void) fprintf(stream, " %11d %11d %11d %11d\n",
  288.         stats.icmp.inHistogram[NET_ICMP_ECHO],
  289.         stats.icmp.inHistogram[NET_ICMP_TIMESTAMP],
  290.         stats.icmp.inHistogram[NET_ICMP_INFO_REQ],
  291.         stats.icmp.inHistogram[NET_ICMP_MASK_REQ]);
  292.  
  293.     (void) fprintf(stream, "\n");
  294.     (void) fprintf(stream, "IP:\n");
  295.     (void) fprintf(stream, " %11s %11s %11s %11s %11s\n",
  296.         "recv: total", "frags","short", "bad sum", "not for us");
  297.     (void) fprintf(stream, " %11d %11d %11d %11d %11d\n",
  298.         stats.ip.totalRcv,
  299.         stats.ip.fragsRcv,
  300.         stats.ip.shortPacket + stats.ip.shortHeader + 
  301.         stats.ip.shortLen,
  302.         stats.ip.badChecksum,
  303.         stats.ip.forwards);
  304.     (void) fprintf(stream, " %11s %11s %11s %11s %11s %11s\n",
  305.         "send: total", "whole","fragmented", "#frags", "dont frag",
  306.         "TO calls");
  307.     (void) fprintf(stream, " %11d %11d %11d %11d %11d %11d\n",
  308.         stats.ip.wholeSent+ stats.ip.fragOnSend,
  309.         stats.ip.wholeSent,
  310.         stats.ip.fragOnSend,
  311.         stats.ip.fragsSent,
  312.         stats.ip.dontFragment,
  313.         stats.ip.fragTimeouts);
  314.  
  315.     (void) fprintf(stream, "\n");
  316.     (void) fprintf(stream, "Raw:\n");
  317.     (void) fprintf(stream, " %11s %11s %11s %11s\n",
  318.         "recv: total", "accepted","send: total", "#bytes");
  319.     (void) fprintf(stream, " %11d %11d %11d %11d\n",
  320.         stats.raw.recv.total,
  321.         stats.raw.recv.accepted,
  322.         stats.raw.send.total,
  323.         stats.raw.send.dataLen);
  324.     (void) fflush(stream);
  325. }
  326.  
  327. static void
  328. ComputeDiff(newPtr, oldPtr, diffPtr)
  329.     register Proc_ResUsage    *newPtr;
  330.     register Proc_ResUsage    *oldPtr;
  331.     register Proc_ResUsage    *diffPtr;
  332. {
  333.     Time_Subtract(newPtr->kernelCpuUsage, oldPtr->kernelCpuUsage, 
  334.             &diffPtr->kernelCpuUsage);
  335.     Time_Subtract(newPtr->userCpuUsage, oldPtr->userCpuUsage, 
  336.             &diffPtr->userCpuUsage);
  337.     diffPtr->numQuantumEnds = newPtr->numQuantumEnds - oldPtr->numQuantumEnds;
  338.     diffPtr->numWaitEvents  = newPtr->numWaitEvents  - oldPtr->numWaitEvents;
  339. }
  340.